home *** CD-ROM | disk | FTP | other *** search
/ Leonardo the Inventor / Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso / LEOWINMV / DATABASE.DIR / 00113_Script_BUILD INDEX < prev    next >
Text File  |  1996-03-28  |  3KB  |  60 lines

  1. -- --------------------------------------------------------
  2. -- Handler buildIndex builds an index out of the contents
  3. -- of a database. It builds the index from fields that
  4. -- are next to each other in the cast window (and therefore
  5. -- receives the parameters "fromCast" and "toCast")
  6.  
  7.  
  8. on buildIndex fromCast, toCast
  9.   repeat with i = fromCast to toCast -- cast numbers of relevant fields
  10.     set currentField = the text of cast i
  11.     repeat with j = 1 to the number of words in currentField
  12.       set currentWord = word j of currentField
  13.       if not(isIgnorableWord(currentWord)) then
  14.         if endsWithPunctuation(currentWord) then
  15.           set currentWord = removePunctuation(currentWord)
  16.         end if
  17.         set indexCast = the number of cast (currentWord && "INDEX")
  18.         if (indexCast <> -1) then -- a field of topics containing the current word already exists
  19.           set temp = the text of cast indexCast
  20.           put RETURN & the name of cast i after temp
  21.           put temp into cast indexCast
  22.         else -- a field of topics containing the current word doesn't exist
  23.           set newFieldNumber = findEmpty(cast (toCast+ 5))
  24.           put the name of cast i into cast newFieldNumber
  25.           set the name of cast newFieldNumber = currentWord && "INDEX"
  26.         end if
  27.       end if
  28.     end repeat
  29.   end repeat
  30. end
  31.  
  32. -- --------------------------------------------------------
  33. -- Handler alphabetizeCasts alphabetizes the casts from
  34. -- "fromCast" to "toCast"
  35.  
  36. on alphabetizeCasts fromCast, toCast
  37.   -- get a temporary cast to use for moving casts around
  38.   set tempCast = findEmpty(cast toCast)
  39.   put "TEMP" into cast tempCast
  40.   set the name of cast tempCast = "tempCast"
  41.   -- bubble sort (n-1) factorial times
  42.   repeat with i = fromCast to toCast - 1
  43.     repeat with j = i+1 to toCast - 1
  44.       set firstCast =  i
  45.       set secondCast = j
  46.       set firstName = the name of cast firstCast
  47.       set secondName = the name of cast secondCast
  48.       if (firstName > secondName) then -- switch the casts around
  49.         set the name of cast tempCast = the name of cast firstCast
  50.         put the text of cast firstCast into cast tempCast
  51.         set the name of cast firstCast = the name of cast secondCast
  52.         put the text of cast secondCast into cast firstCast
  53.         set the name of cast secondCast = the name of cast tempCast
  54.         put the text of cast tempCast into cast secondCast
  55.         set the name of cast tempCast = "tempCast"
  56.         put "TEMP" into cast tempCast
  57.       end if
  58.     end repeat
  59.   end repeat
  60. end